﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WinForms = System.Windows.Forms;

namespace PearTunes.Client
{
    /// <summary>
    /// Interaction logic for UserSettingsForm.xaml
    /// </summary>
    public partial class UserSettingsForm : Window
    {
        public UserSettingsForm()
        {
            InitializeComponent();
            userNameTextBox.Text = Properties.Settings.Default.UserName;
            userPassTextBox.Text = Properties.Settings.Default.Password;
            musicPathTextBox.Text = Properties.Settings.Default.localMusicPath;
            playlistPathTextBox.Text = Properties.Settings.Default.localPlaylistPath;
        }

        private void Save()
        {
            Properties.Settings.Default.UserName=userNameTextBox.Text;
            Properties.Settings.Default.Password=userPassTextBox.Text;
            Properties.Settings.Default.localMusicPath= musicPathTextBox.Text;
            Properties.Settings.Default.localPlaylistPath = playlistPathTextBox.Text;

            Properties.Settings.Default.Save();
        }

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            Save();
            this.DialogResult = true;
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void musicPathBrowseButton_Click(object sender, RoutedEventArgs e)
        {
            WinForms.FolderBrowserDialog folderDialog = new WinForms.FolderBrowserDialog();
            if (folderDialog.ShowDialog() == WinForms.DialogResult.OK)
            {
                musicPathTextBox.Text = folderDialog.SelectedPath; 
            }

        }

        private void playlistPathBrowseButton_Click(object sender, RoutedEventArgs e)
        {
            WinForms.FolderBrowserDialog folderDialog = new WinForms.FolderBrowserDialog();
            if (folderDialog.ShowDialog() == WinForms.DialogResult.OK)
            {
                playlistPathTextBox.Text = folderDialog.SelectedPath;
            }
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            MainWindow.LoginUser();
        }
    }
}
